package com.zou.study.zmy;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

/**
 * <br/>Date 2021/8/17
 * <br/>Time 22:59:30
 *
 * @author _blank
 */
public class Interview {

    public static void main(String[] args) throws IOException {
        final File file = new File("C:\\Users\\_blank\\Desktop\\assert");
        if (!file.exists()) {
            return;
        }

        final File[] files = file.listFiles();
        if (Objects.isNull(files)) {
            return;
        }

        for (final File fff : files) {
            final byte[] bytes;

            try (FileInputStream fis = new FileInputStream(fff)) {
                bytes = new byte[28];
                final int read = fis.read(bytes, 0, 28);
                if (read == -1) {
                    continue;
                }
                System.out.print(Arrays.toString(bytes) + "    ");
            }

            final StringBuilder sb = new StringBuilder(bytes.length * 3);
            for (byte aByte : bytes) {
                final int i1 = aByte & 0xFF;
                final String toHexString = Integer.toHexString(i1);
                if (toHexString.length() == 1) {
                    sb.append("0");
                }
                sb.append(toHexString);
            }

            final String lowerCase = sb.toString().toLowerCase();
            System.out.print(lowerCase + "    ");

            if (lowerCase.startsWith("89504e47")) {
//                final File dest = new File(fff.getParentFile(), fff.getName() + ".png");
//                final boolean b = fff.renameTo(dest);
//                System.out.println(b);
            } else if (lowerCase.startsWith("ffd8ffe1")/*lowerCase.startsWith("ffd8ffe0")*/) {
//                final boolean b = fff.renameTo(new File(fff.getParentFile(), fff.getName() + ".jpg"));
//                System.out.println(b);
            }
            System.out.println();
        }
    }

    public String randomDeleteChar(String str) {
        return null;
    }

}
